# Maintainer: Steven Guikal <void@fluix.one>
pkgname=yggdrasil
pkgver=0.5.5
pkgrel=3
pkgdesc="An experiment in scalable routing as an encrypted IPv6 overlay network"
url="https://yggdrasil-network.github.io/"
arch="all"
license="LGPL-3.0-only"
makedepends="go"
install="$pkgname.post-install"
source="
	$pkgname-$pkgver.tar.gz::https://github.com/yggdrasil-network/yggdrasil-go/archive/v$pkgver.tar.gz
	$pkgname.confd
	$pkgname.initd
	modules.conf
"
options="net" # for downloading Go modules
builddir="$srcdir/$pkgname-go-$pkgver"
subpackages="$pkgname-openrc"

export GOCACHE="${GOCACHE:-"$srcdir/go-cache"}"
export GOTMPDIR="${GOTMPDIR:-"$srcdir"}"
export GOMODCACHE="${GOMODCACHE:-"$srcdir/go"}"

build() {
	go mod vendor
	pkgsrc=github.com/yggdrasil-network/yggdrasil-go/src/version
	ldflags="-X $pkgsrc.buildName=$pkgname -X $pkgsrc.buildVersion=$pkgver"
	for cmd in yggdrasil yggdrasilctl
	do
		go build \
			-trimpath \
			-mod=vendor \
			-ldflags "-extldflags \"$LDFLAGS\" $ldflags" \
			./cmd/$cmd
	done
}

check() {
	go test ./...
}

package() {
	install -Dm755 yggdrasil "$pkgdir"/usr/bin/yggdrasil
	install -Dm755 yggdrasilctl "$pkgdir"/usr/bin/yggdrasilctl
	install -Dm644 "$srcdir"/yggdrasil.confd \
		"$pkgdir"/etc/conf.d/yggdrasil
	install -Dm755 "$srcdir"/yggdrasil.initd \
		"$pkgdir"/etc/init.d/yggdrasil
	install -Dm644 "$srcdir"/modules.conf \
		"$pkgdir"/usr/lib/modules-load.d/yggdrasil.conf
}

sha512sums="
13ee5c719335d7a599019d004cd8d82883c7a2beb707de968a0934982364a0f70982f14157bd9aaabda9595f194594901a9158cfeb272491a71b5392abd79dc4  yggdrasil-0.5.5.tar.gz
c506b12deb6611202fef61826b88fa8432c228189935176a85d860a3d97f6d2952ff1d05235482d762cad2dee64b48e8266f5c5ee68f6ce494d66067cb09b769  yggdrasil.confd
2873979dbd5a0146dc2a151283388bfd04d456bf1182060214ab063d0121cd94129e17f476da6f0613f28b663fdd4c65f38473923cd8966b7b551483ad6d13ab  yggdrasil.initd
871b650ff982be061532b4c5fe4812f41e6e2c58fc69b24f8a745f9a43389da44e742a69b0467b3c3d9e2b031af0728e20f10fa4584695c4f5ac87768a1fd34e  modules.conf
"
